import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart';
import 'package:well_known/pages/entry/entry_add.dart';
import 'package:well_known/pages/home/home.dart';
import 'package:well_known/pages/search/search.dart';
import 'package:well_known/pages/setting.dart';
import 'package:well_known/pages/tong_diao_zhe/tong_diao_zhe.dart';

import 'config/configs.dart';
import 'global_cubit.dart';

final GlobalCubit globalCubit = GlobalCubit();

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await globalCubit.init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    var initRoute = (globalCubit.state.user.email == "" && globalCubit.state.user.phone == "") ? Pages.home.toString() : Pages.home.toString();
    return MaterialApp(
      title: '信用社',
      localizationsDelegates: [FlutterQuillLocalizations.delegate],
      // supportedLocales: [Locale('zh', 'CN')],
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.transparent),
        primaryColor: Colors.transparent,
        scaffoldBackgroundColor: Colors.transparent,
        appBarTheme: const AppBarTheme(color: Colors.blue, elevation: 0),
        textTheme: const TextTheme(),
      ),
      routes: {
        Pages.home.toString(): (context) => const HomePage(),
        Pages.setting.toString(): (context) => const SettingPage(),
        Pages.tongDiaoZhe.toString(): (context) => const TongDiaoZhePage(),
        Pages.search.toString(): (context) => const SearchPage(),
        Pages.entryAdd.toString(): (context) => const EntryAddPage(),
      },
      initialRoute: initRoute,
    );
  }
}
